﻿<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<head>
<title>修改名师</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<%=request.getContextPath()%>/style/adminStyle.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script src="<%=request.getContextPath()%>/js/public.js"></script>
<script type="text/javascript">

function show1(f) {
    var str = "";
    for (var i = 0; i < f.length; i++) {
        var reader = new FileReader();
        reader.readAsDataURL(f[i]);
        reader.onload = function (e) {
            str += "<img  height='50' width='50' id='img' src='" + e.target.result + "'/>";
            $("#img1")[0].outerHTML = str;
        }
    }        
}
</script>
</head>
<body>
 <div class="wrap">
  <div class="page-title">
    <span class="modular fl"><i></i><em>修改名师</em></span>
  </div>
  
  <table class="list-style">
   <tr>
    <td style="text-align:right;">ID：</td>
    <td>
     <input type="text" class="textBox" id="id" value="${res.id}" readonly="readonly"/>
    </td>
   </tr>
   <tr>
    <td style="text-align:right;width:15%;">名称：</td>
    <td>
     <input type="text" class="textBox" id="iname" value="${res.iname}"/>
    </td>
   </tr>
   <tr>
    <td style="text-align:right;width:10%;">性别：</td>
    <td>
     
       <c:if test="${res.sex==1}">
     	<select class="textBox" id="sex">
    	<option value="1">男</option>
    	<option value="0">女</option>
    	</select>
		</c:if>
		
       <c:if test="${res.sex==0}">
        <select class="textBox" id="sex">
    	<option value="0">女</option>
    	<option value="1">男</option>
    	</select>
		</c:if>
     
    </td>
   </tr>
   <tr>
    <td style="text-align:right;width:15%;">擅长领域：</td>
    <td>
     <input type="text" class="textBox" id="type" value="${res.type}"/>
    </td>
   </tr>
   <tr>
    <td style="text-align:right;width:15%;">UID/电话：</td>
    <td>
     <input type="text" class="textBox" id="wechatnumber" value="${res.wechatnumber}"/>
    </td>
   </tr>
   
   <tr>
    <td style="text-align:right;">头像：</td>
     <td style="width: 50px; height: 50px;"><img src="${res.url}" height="50" width="50" id="img1" /><input type="file" id="file1" class="inputfile1" onchange="show1(this.files)"  accept="image/*"/> 
	</td>
   </tr>
   
   <tr>
    <td style="text-align:right;">名师介绍：</td>
    <td>
     <textarea class="textarea" id="introduce" >${res.introduce}</textarea>
    </td>
   </tr>
   <tr>
    <td style="text-align:right;"></td>
    <td><input type="button" value="修改" class="tdBtn" onclick="return resInst()"/>
    <span style="color:red">&nbsp;*若需修改,请重新上传图片</span></td>
   </tr>
  </table>
 </div>
 <script type="text/javascript">
 function resInst(){
		var msg = "您确定要修改名师信息吗？\n\n请确认！";
		var id=$("#id").val();
		var iname=$("#iname").val();
		var sex=$("#sex").val();
		var type=$("#type").val();
		var wechatnumber=$("#wechatnumber").val();
		var introduce=$("#introduce").val();
		var file1 = $("#file1")[0].files[0];
		
	
		
		var formData = new FormData();
		formData.append("id",id);
		formData.append("iname",iname);
		formData.append("sex",sex);
	  	formData.append("type",type);
		formData.append("file",file1);
		formData.append("introduce",introduce);
		formData.append("wechatnumber",wechatnumber);
		
		if (confirm(msg)==true){
			$.ajax({
				"url":"${pageContext.request.contextPath}/Administrators/add_category2.do",
				"data":formData,
				"type":"POST",
				"dataType":"json",
				"cache": false,
				"processData": false,
				"contentType": false,
				async: false,
				"success":function(o){
					if(o.state==1){
						 alert("修改成功");
						window.location="${pageContext.request.contextPath}/Administrators/master_list.do";
					}else{
						 alert("修改失败");
					}
					
			
				}});
			
		return true;
		}else{
		return false;
		}
		}
 
 
 </script>
</body>
</html>